package link.chengguo.orangemall.modules.system.rest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import link.chengguo.orangemall.logging.aop.log.Log;
import link.chengguo.orangemall.modules.activity.service.*;
import link.chengguo.orangemall.modules.cart.service.OrangeStoreCartService;
import link.chengguo.orangemall.modules.category.service.OrangeStoreCategoryService;
import link.chengguo.orangemall.modules.order.service.OrangeStoreOrderCartInfoService;
import link.chengguo.orangemall.modules.order.service.OrangeStoreOrderService;
import link.chengguo.orangemall.modules.order.service.OrangeStoreOrderStatusService;
import link.chengguo.orangemall.modules.product.service.*;
import link.chengguo.orangemall.modules.service.OrangeStoreProductBrowseService;
import link.chengguo.orangemall.modules.shop.service.OrangeSystemStoreStaffService;
import link.chengguo.orangemall.modules.user.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 钟业海
 * @Date: 2020/8/19 10:54
 */
@Slf4j
@Api(tags = "系统：数据清除")
@RestController
@RequestMapping("/api/dataDelete")
public class DataController {

    @Autowired
    private OrangeUserService userService;
    @Autowired
    private OrangeUserAddressService addressService;
    @Autowired
    private OrangeUserBillService billService;
    @Autowired
    private OrangeUserExtractService extractService;
    @Autowired
    private OrangeUserLevelService levelService;
    @Autowired
    private OrangeUserRechargeService rechargeService;
    @Autowired
    private OrangeUserSignService signService;
    @Autowired
    private OrangeUserTaskFinishService taskFinishService;
    @Autowired
    private OrangeStoreProductBrowseService browseService;
    @Autowired
    private OrangeStoreProductRelationService relationService;
    @Autowired
    private OrangeStoreProductReplyService replyService;
    @Autowired
    private OrangeStoreBargainUserService bargainUserService;
    @Autowired
    private OrangeStoreBargainUserHelpService bargainUserHelpService;
    @Autowired
    private OrangeStoreCartService cartService;
    @Autowired
    private OrangeStoreCouponIssueUserService couponIssueUserService;
    @Autowired
    private OrangeStoreCouponUserService couponUserService;
    @Autowired
    private OrangeStoreOrderService orderService;
    @Autowired
    private OrangeStoreOrderCartInfoService orderCartInfoService;
    @Autowired
    private OrangeStoreOrderStatusService orderStatusService;
    @Autowired
    private OrangeStorePinkService pinkService;
    @Autowired
    private OrangeStoreVisitService visitService;
    @Autowired
    private OrangeSystemStoreStaffService storeStaffService;
    @Autowired
    private OrangeStoreProductService productService;
    @Autowired
    private OrangeStoreProductAttrService attrService;
    @Autowired
    private OrangeStoreProductAttrResultService attrResultService;
    @Autowired
    private OrangeStoreProductAttrValueService attrValueService;
    @Autowired
    private OrangeStoreSeckillService seckillService;
    @Autowired
    private OrangeStoreCombinationService combinationService;
    @Autowired
    private OrangeStoreCategoryService categoryService;



    @Log("用户数据清除")
    @ApiOperation("用户数据清除")
    @PreAuthorize("@el.check('admin','dataDelete:user')")
    @DeleteMapping(value = "/user")
    public ResponseEntity<Object> removeUserData(){
        QueryWrapper queryWrapper = new QueryWrapper();
        userService.remove(queryWrapper);
        addressService.remove(queryWrapper);
        billService.remove(queryWrapper);
        extractService.remove(queryWrapper);
        levelService.remove(queryWrapper);
        rechargeService.remove(queryWrapper);
        signService.remove(queryWrapper);
        taskFinishService.remove(queryWrapper);
        browseService.remove(queryWrapper);
        relationService.remove(queryWrapper);
        replyService.remove(queryWrapper);
        bargainUserService.remove(queryWrapper);
        bargainUserHelpService.remove(queryWrapper);
        cartService.remove(queryWrapper);
        couponIssueUserService.remove(queryWrapper);
        couponUserService.remove(queryWrapper);
        orderService.remove(queryWrapper);
        orderCartInfoService.remove(queryWrapper);
        orderStatusService.remove(queryWrapper);
        pinkService.remove(queryWrapper);
        visitService.remove(queryWrapper);
        storeStaffService.remove(queryWrapper);
        return new ResponseEntity<>(HttpStatus.OK);
    }


    @Log("商品数据清除")
    @ApiOperation("商品数据清除")
    @PreAuthorize("@el.check('admin','dataDelete:product')")
    @DeleteMapping(value = "/product")
    public ResponseEntity<Object> removeProductData(){
        QueryWrapper queryWrapper = new QueryWrapper();
        productService.remove(queryWrapper);
        attrService.remove(queryWrapper);
        attrResultService.remove(queryWrapper);
        attrValueService.remove(queryWrapper);
        seckillService.remove(queryWrapper);
        browseService.remove(queryWrapper);
        relationService.remove(queryWrapper);
        replyService.remove(queryWrapper);
        bargainUserService.remove(queryWrapper);
        bargainUserHelpService.remove(queryWrapper);
        cartService.remove(queryWrapper);
        couponIssueUserService.remove(queryWrapper);
        couponUserService.remove(queryWrapper);
        pinkService.remove(queryWrapper);
        visitService.remove(queryWrapper);
        combinationService.remove(queryWrapper);
        categoryService.remove(queryWrapper);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
